package com.slz3.business.module.systemManagement.sysUser.steward;

import com.slz3.business.frame.response.RR;
import com.slz3.business.frame.response.ResInfo;
import com.slz3.business.module.systemManagement.sysUser.domain.SysUser;
import com.slz3.business.module.systemManagement.sysUser.domain.SysUserCondition;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

public class SysUserResController {

    static Mono<ServerResponse> add(ServerRequest req, SysUser sysUser) {
        if (SysUserResUnsafeValid.add(req, sysUser)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return SysUserResAtomic.add_$SysUserUpdateLock(req, sysUser);
        }
    }

    static final Mono<ServerResponse> delete(ServerRequest req, SysUserCondition sysUserCondition) {
        if (SysUserResUnsafeValid.delete(req, sysUserCondition)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return SysUserResAtomic.delete_$SysUserUpdateLock(req, sysUserCondition);
        }
    }

    static Mono<ServerResponse> modify(ServerRequest req, SysUser sysUser) {
        if (SysUserResUnsafeValid.modify(req, sysUser)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return SysUserResAtomic.modify_$SysUserUpdateLock(req, sysUser);
        }
    }

    static Mono<ServerResponse> list(ServerRequest req) {
        if (SysUserResUnsafeValid.list(req)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return SysUserResExecutor.list(req);
        }
    }

    static Mono<ServerResponse> info(ServerRequest req) {
        if (SysUserResUnsafeValid.info(req)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return SysUserResAtomic.info_$SysUserUpdateLock(req);
        }
    }

    static Mono<ServerResponse> choice(ServerRequest req) {
        if (SysUserResUnsafeValid.choice(req)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return SysUserResExecutor.choice(req);
        }
    }

    static final Mono<ServerResponse> auditSubmit(ServerRequest req, SysUserCondition sysUserCondition) {
        //
        if (SysUserResUnsafeValid.auditSubmit(req, sysUserCondition)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return SysUserResAtomic.auditSubmit_$SysUserUpdateLock(req, sysUserCondition);
        }
    }

    static final Mono<ServerResponse> audit(ServerRequest req, SysUserCondition sysUserCondition) {
        if (SysUserResUnsafeValid.audit(req, sysUserCondition)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return SysUserResAtomic.audit_$SysUserUpdateLock(req, sysUserCondition);
        }
    }

    static final Mono<ServerResponse> auditReject(ServerRequest req, SysUserCondition sysUserCondition) {
        if (SysUserResUnsafeValid.auditReject(req, sysUserCondition)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return SysUserResAtomic.auditReject_$SysUserUpdateLock(req, sysUserCondition);
        }
    }

    static final Mono<ServerResponse> usingEnable(ServerRequest req, SysUserCondition sysUserCondition) {
        if (SysUserResUnsafeValid.usingEnable(req, sysUserCondition)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return SysUserResAtomic.usingEnable_$SysUserUpdateLock(req, sysUserCondition);
        }
    }

    static final Mono<ServerResponse> usingDisable(ServerRequest req, SysUserCondition sysUserCondition) {
        if (SysUserResUnsafeValid.usingDisable(req, sysUserCondition)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return SysUserResAtomic.usingDisable_$SysUserUpdateLock(req, sysUserCondition);
        }
    }

    public static Mono<? extends ServerResponse> register(ServerRequest req, SysUserCondition sysUserCondition) {
        // T-O-D-O 注册
        return null;
    }

    public static Mono<ServerResponse> login(ServerRequest req, SysUser sysUser) {
        // TODO 登录
        if (!SysUserResUnsafeValid.login(req, sysUser)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description("请填写登陆用户和密码").build());
        } else {
            return SysUserResExecutor.login(req, sysUser);
        }
    }

    public static Mono<? extends ServerResponse> logout(ServerRequest req, SysUserCondition sysUserCondition) {
        // TODO 退出
        SysUserConverter.logout(req);
        return RR.success(req, ResInfo.builder().code(RR.SUCCESS).build());
    }
}
